
#ifndef _COMMON_SETTINGS_
#define _COMMON_SETTINGS_

#define kBundleIdentifier "com.udm.Octogris"

typedef long long int64;

static const int kParamsPerSource = 3;
static const int kParamsPerSpeakers = 4;

//#define kLevelAttackParam (0)
//#define kLevelReleaseParam (1)
#define kParamSmoothParam (0)
#define kLinkSourcesParam (1)
#define kShowGridLinesParam (2)
#define kMovementModeParam (3)
#define kShowLevelsParam (4)
#define kTakeAttenuationParam (5)
//#define kEnableJoystickParam (6)
static const int kConstantParameters = 6;

static const float kLevelAttackMin = 0.01;
static const float kLevelAttackMax = 100;
static const float kLevelAttackDefault = 0.05;

static const float kLevelReleaseMin = 1;
static const float kLevelReleaseMax = 500;
static const float kLevelReleaseDefault = 100;

static const float kParamSmoothMin = 1;
static const float kParamSmoothMax = 200;
static const float kParamSmoothDefault = 10;


// apple reserves 0 to 63999
#define kProperty(x) (200000 + x)
static const AudioUnitPropertyID kNumberOfSourcesPropertyID = kProperty(0);
static const AudioUnitPropertyID kNumberOfSpeakersPropertyID = kProperty(1);
static const AudioUnitPropertyID kCalculateLevelsPropertyID = kProperty(2);
static const AudioUnitPropertyID kLevelsPropertyID = kProperty(3);
static const AudioUnitPropertyID kProcessCounterPropertyID = kProperty(4);


enum { kSourceX = 0, kSourceY = 1, kSourceD = 2 };
#define ParamForSourceX(v) (kConstantParameters + kSourceX + v * kParamsPerSource)
#define ParamForSourceY(v) (kConstantParameters + kSourceY + v * kParamsPerSource)
#define ParamForSourceD(v) (kConstantParameters + kSourceD + v * kParamsPerSource)

enum { kSpeakerX = 0, kSpeakerY = 1, kSpeakerA = 2, kSpeakerM = 3 };
#define ParamForSpeakerX(v) (kConstantParameters + kSpeakerX + mNumberOfSources * kParamsPerSource + v * kParamsPerSpeakers)
#define ParamForSpeakerY(v) (kConstantParameters + kSpeakerY + mNumberOfSources * kParamsPerSource + v * kParamsPerSpeakers)
#define ParamForSpeakerA(v) (kConstantParameters + kSpeakerA + mNumberOfSources * kParamsPerSource + v * kParamsPerSpeakers)
#define ParamForSpeakerM(v) (kConstantParameters + kSpeakerM + mNumberOfSources * kParamsPerSource + v * kParamsPerSpeakers)

//Hacking link movement in here. It would be better to have it amongst the constant parameters
//But putting it there bumps up the ID for each of the speaker/source params
//And so makes it incompatible with legacy versions of Octogris.
//Therefore:
#define kLinkMovementParam	(kConstantParameters + mNumberOfSources * kParamsPerSource + mNumberOfSpeakers * kParamsPerSpeakers)

#define mNumberOfParameters (kConstantParameters + mNumberOfSources * kParamsPerSource + mNumberOfSpeakers * kParamsPerSpeakers + 1)

static const float kSourceDefaultRadius = 0.4;

static const float kSourceMinDistance = 2.5;
static const float kSourceMaxDistance = 20;
static const float kSourceDefaultDistance = 5;

static const float kSpeakerMinAttenuation = -70;
static const float kSpeakerMaxAttenuation = 20;
static const float kSpeakerDefaultAttenuation = 0;

#define dbToLinear(db)		( powf(10.f, (db) * 0.05f) )
#define linearToDb(linear)	( log10f(linear) * 20.f )

#define MAX_JOYBUTTS 12

#endif /* _COMMON_SETTINGS_ */
